Chapter 8 Differential abundance analysis

8.1 CC acclimation vs post2

8.1.1 Enrichment analysis: Ancombc2

8.1.1.1 MAG level

8.2 WC acclimation vs post2

8.2.1 Enrichment analysis: Ancombc2

8.2.1.1 MAG level

8.3 CI acclimation vs post2

8.3.1 Enrichment analysis: Ancombc2

8.3.1.1 MAG level

8.4 post2 CC and CI

8.4.1 Enrichment analysis: Ancombc2

8.4.1.1 MAG level

8.5 post2 WC and CI

8.5.1 Enrichment analysis: Ancombc2

8.5.1.1 MAG level

8.6 Community level plots

accli_post2<-sample_metadata%>% 
  filter(time_point == "1_Acclimation"|time_point == "6_Post-FMT2")
accli_post2$newID<-paste(accli_post2$type, "_", accli_post2$time_point)

GIFTs_functions_community %>%
  as.data.frame() %>%
  rownames_to_column("sample") %>%
  left_join(accli_post2, by = join_by(sample == Tube_code)) %>%
  filter(time_point == "1_Acclimation"|time_point == "6_Post-FMT2") %>%
  select(c(1:21, 27,30)) %>%
  pivot_longer(-c(sample,type,time_point),names_to = "trait", values_to = "value") %>%
  mutate(trait = case_when(
    trait %in% GIFT_db$Code_function ~ GIFT_db$Function[match(trait, GIFT_db$Code_function)],
    TRUE ~ trait
  )) %>%
  mutate(trait=factor(trait,levels=unique(GIFT_db$Function))) %>%
  ggplot(aes(x=value, y=time_point, group=time_point, fill=type, color=type)) +
  geom_boxplot() +
  scale_color_manual(name="type",
                     breaks=c("Control","Hot_control", "Treatment"),
                     labels=c("Cold-Cold","Hot-Hot", "Cold-Hot"),
                     values=c("#4477AA","#d57d2c","#76b183")) +
  scale_fill_manual(name="type",
                    breaks=c("Control","Hot_control", "Treatment"),
                    labels=c("Cold-Cold","Hot-Hot", "Cold-Hot"),
                    values=c("#4477AA50","#d57d2c50","#76b18350")) +
  facet_grid(trait ~ type, space="free", scales="free") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
        strip.text.y = element_text(angle = 0)) + 
  labs(y="Traits",x="Metabolic capacity index")

GIFTs_elements_community_merged<-GIFTs_elements_community %>%
    as.data.frame() %>%
    rownames_to_column(var="sample") %>%
    filter(sample!="AD69") %>%
    pivot_longer(!sample,names_to="trait",values_to="gift") %>%
    left_join(sample_metadata, by = join_by(sample == Tube_code))%>%
    filter(time_point=="1_Acclimation"|time_point == "6_Post-FMT2")%>%
    mutate(functionid = substr(trait, 1, 3)) %>%
    mutate(trait = case_when(
      trait %in% GIFT_db$Code_element ~ GIFT_db$Element[match(trait, GIFT_db$Code_element)],
      TRUE ~ trait
    )) %>%
    mutate(functionid = case_when(
      functionid %in% GIFT_db$Code_function ~ GIFT_db$Function[match(functionid, GIFT_db$Code_function)],
      TRUE ~ functionid
    )) %>%
    mutate(trait=factor(trait,levels=unique(GIFT_db$Element))) %>%
    mutate(functionid=factor(functionid,levels=unique(GIFT_db$Function)))

# Create an interaction variable for time_point and sample
GIFTs_elements_community_merged$interaction_var <- interaction(GIFTs_elements_community_merged$sample, GIFTs_elements_community_merged$time_point)
  
ggplot(GIFTs_elements_community_merged,aes(x=interaction_var,y=trait,fill=gift)) +
        geom_tile(colour="white", linewidth=0.2)+
        scale_fill_gradientn(colours=rev(c("#d53e4f", "#f46d43", "#fdae61", "#fee08b", "#e6f598", "#abdda4", "#ddf1da")))+
        facet_grid(functionid ~ type, scales="free",space="free") +
        theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, size=5),
              strip.text.y = element_text(angle = 0)) + 
        labs(y="Traits",x="Time_point",fill="GIFT")+
  scale_x_discrete(labels = function(x) gsub(".*\\.", "", x))

8.7 Wilcoxon comparison

8.7.1 Community elements differences: in CC acclimation vs post2

difference_table_CC %>% 
  filter(group_color=="Acclimation")
[1] Elements    Acclimation Post2       Function    Element     Difference  group_color
<0 rows> (or 0-length row.names)

8.7.2 Community elements differences: in CI acclimation vs post2

difference_table_CI %>% 
  filter(group_color=="Acclimation")

8.7.3 Community elements differences: in WC acclimation vs post2

difference_table_WC %>% 
  filter(group_color=="Acclimation")

8.7.4 Comparison of both population in wild samples

difference_table_WC %>% 
  filter(group_color=="Acclimation")
  Elements Acclimation      Post2                              Function          Element Difference group_color
1    D0301  0.03445823 0.02175758             Sugar degradation_Lactose          Lactose 0.01270065 Acclimation
2    B0711  0.31689890 0.23431920 Vitamin biosynthesis_Menaquinone (K2) Menaquinone (K2) 0.08257970 Acclimation

####Butiryc acid biosynthesis

8.7.5 Comparison of both population in acclimation samples

8.7.6 Comparison of CC and CI in post2 samples

8.7.7 Comparison of CI and WC in post2 samples